Merge pull request #1359 from dsander/docker

Improve docker images

Dominik Sander 8 years ago
parent
commit
9fbf31ced1

+ 38 - 0
.dockerignore

@@ -0,0 +1,38 @@
1
+.git
2
+tmp
3
+log
4
+doc
5
+spec
6
+media
7
+.openshift
8
+.bundle
9
+vendor/bundle
10
+db/*.sqlite3
11
+public/system/*
12
+coverage
13
+spec/tmp/*
14
+.travis.yml
15
+build_docker_image.sh
16
+
17
+# Copied from .gitignore
18
+*.rbc
19
+*.sassc
20
+.sass-cache
21
+capybara-*.html
22
+.rspec
23
+!/tmp/.gitkeep
24
+**.orig
25
+rerun.txt
26
+pickle-email-*.html
27
+.idea/
28
+.DS_Store
29
+.env
30
+deployment/tmp
31
+deployment/cookbooks
32
+.vagrant
33
+.*un~
34
+.ruby-gemset
35
+.ruby-version
36
+manifest.yml
37
+config/unicorn.rb
38
+db/schema.rb

+ 25 - 5
.travis.yml

@@ -1,11 +1,29 @@
1
-sudo: false
1
+dist: trusty
2
+sudo: required
2 3
 language: ruby
4
+services:
5
+  - docker
6
+  - postgresql
3 7
 env:
4 8
   global:
5 9
     - APP_SECRET_TOKEN=b2724973fd81c2f4ac0f92ac48eb3f0152c4a11824c122bcf783419a4c51d8b9bba81c8ba6a66c7de599677c7f486242cf819775c433908e77c739c5c8ae118d
10
+    - secure: fzmSI7PQz6CJiIJNAtLAuy3TMmYCrK4bUil3uufh8JkHfpSGWOZt2i6fZ8yZ7pzwG5Aw7eZDgdFsNcEPJlgUDJhlwjg+QxCJslhotTQ9qI3Ieo85peWlU9dZFTOZcrCu0net/hY2FE4ZpTRb5r8A/DRv9ukA8P8tShhePCjckgg=
11
+    - secure: YjW07LpRSiC9xB6PhLQ4LVv2VphvF3IacV43PLfvzdagjy14yAwKXTUlSadgRaMbndB2dlCTe3YcY11a/xtX/2HDrF14NHPXQdL7e2dJUS3CDLSKZK26x1SOiaaDIrl1jO1xr5kOUd+564MAcNUzDTJQR4CrWl/5t6EwW4iYQVc=
12
+    - secure: RJiSTB9Anax6uL6mgYY1m42w71ohlsfIlVCk7ho6W19ZfSzQOfom0mBdeNwfgmXsMMnvnqatfxSg8k3C//pRtI/tjzAovHd7t1YIN1IkDNf9uSpzrIeXXc4fSHaVxnl512oI/eBQy9MSBjVZjrg5XEzLKKEGsZCai+ZKB4PS+nM=
6 13
   matrix:
7 14
     - DATABASE_ADAPTER=mysql2
8 15
     - DATABASE_ADAPTER=postgresql DATABASE_USERNAME=postgres
16
+    - DOCKER_IMAGE=cantino/huginn-single-process DOCKERFILE=docker/single-process/Dockerfile
17
+    - DOCKER_IMAGE=cantino/huginn DOCKERFILE=docker/multi-process/Dockerfile
18
+matrix:
19
+  exclude:
20
+    - env: DOCKER_IMAGE=cantino/huginn-single-process DOCKERFILE=docker/single-process/Dockerfile
21
+    - env: DOCKER_IMAGE=cantino/huginn DOCKERFILE=docker/multi-process/Dockerfile
22
+  include:
23
+    - rvm: 2.3.0
24
+      env: DATABASE_ADAPTER=mysql2 DOCKER_IMAGE=cantino/huginn-single-process DOCKERFILE=docker/single-process/Dockerfile
25
+    - rvm: 2.3.0
26
+      env: DATABASE_ADAPTER=mysql2 DOCKER_IMAGE=cantino/huginn DOCKERFILE=docker/multi-process/Dockerfile
9 27
 rvm:
10 28
 - 2.0.0
11 29
 - 2.1
@@ -13,9 +31,11 @@ rvm:
13 31
 - 2.3.0
14 32
 cache: bundler
15 33
 bundler_args: --without development production
16
-before_script:
17
-- bundle exec rake db:create db:migrate
18
-script: bundle exec rake
34
+before_install:
35
+  - sudo apt-get -qq update
36
+  - sudo apt-get install -y mysql-server
37
+script:
38
+  - if [ -z "${DOCKER_IMAGE}" ]; then bundle exec rake db:create db:migrate && bundle exec rake; else ./build_docker_image.sh; fi
19 39
 notifications:
20 40
   irc:
21 41
     channels:
@@ -29,4 +49,4 @@ notifications:
29 49
       - https://webhooks.gitter.im/e/5f92cc0393c6f1defe0d
30 50
     on_success: change  # options: [always|never|change] default: always
31 51
     on_failure: always  # options: [always|never|change] default: always
32
-    on_start: false     # default: false
52
+    on_start: never     # options: [always|never|change] default: never

+ 14 - 0
build_docker_image.sh

@@ -0,0 +1,14 @@
1
+#!/bin/bash
2
+set -ev
3
+
4
+docker pull $DOCKER_IMAGE
5
+docker build -t $DOCKER_IMAGE -f $DOCKERFILE .
6
+
7
+if [[ -n "${DOCKER_USER}" && "${TRAVIS_PULL_REQUEST}" = 'false' && "${TRAVIS_BRANCH}" = "master" ]]; then
8
+  docker login -e $DOCKER_EMAIL -u $DOCKER_USER -p $DOCKER_PASS
9
+  docker tag $DOCKER_IMAGE $DOCKER_IMAGE:$TRAVIS_COMMIT
10
+  docker push $DOCKER_IMAGE
11
+  docker push $DOCKER_IMAGE:$TRAVIS_COMMIT
12
+else
13
+  echo "Docker image are only pushed for builds of the master branch when Docker Hub credentials are present."
14
+fi

+ 17 - 4
docker/multi-process/Dockerfile

@@ -1,12 +1,25 @@
1
-FROM cantino/huginn-single-process:latest
1
+FROM ubuntu:14.04
2 2
 MAINTAINER Andrew Cantino
3 3
 
4
-WORKDIR /app
4
+ADD docker/scripts/prepare /scripts/prepare
5
+RUN /scripts/prepare
5 6
 
6
-ADD scripts/standalone-packages /scripts/standalone-packages
7
+ADD docker/multi-process/scripts/standalone-packages /scripts/standalone-packages
7 8
 RUN /scripts/standalone-packages
8 9
 
9
-ADD scripts/init /scripts/init
10
+WORKDIR /app
11
+
12
+ADD ["Gemfile", "Gemfile.lock", "/app/"]
13
+ADD lib/gemfile_helper.rb /app/lib/
14
+ADD vendor/gems /app/vendor/gems
15
+
16
+RUN chown -R huginn:huginn /app && \
17
+    sudo -u huginn -H echo "gem 'sqlite3', '~> 1.3.11'" >> /app/Gemfile && \
18
+    sudo -u huginn -H LC_ALL=en_US.UTF-8 RAILS_ENV=production ON_HEROKU=true bundle install --without test development --path vendor/bundle -j 4
19
+COPY . /app
20
+
21
+ADD ["docker/scripts/setup", "docker/multi-process/scripts/init", "/scripts/"]
22
+RUN /scripts/setup
10 23
 
11 24
 VOLUME /var/lib/mysql
12 25
 

+ 2 - 2
docker/multi-process/README.md

@@ -96,9 +96,9 @@ For variables in the .env.example that are commented out, the default is to not
96 96
 
97 97
 ## Building on your own
98 98
 
99
-You don't need to do this on your own, because there is an [automated build](https://registry.hub.docker.com/u/cantino/huginn/) for this repository, but if you really want:
99
+You don't need to do this on your own, because there is an [automated build](https://registry.hub.docker.com/u/cantino/huginn/) for this repository, but if you really want run this command in the Huginn root directory:
100 100
 
101
-    docker build --rm=true --tag={yourname}/huginn .
101
+    docker build --rm=true --tag={yourname}/huginn -f docker/multi-process/Dockerfile .
102 102
 
103 103
 ## Source
104 104
 

+ 35 - 25
docker/multi-process/docker-compose.yml

@@ -1,28 +1,38 @@
1
-mysqldata:
2
-  image: mysql:5.7
3
-  command: /bin/true
1
+# This needs at least compose 1.6.0
2
+version: '2'
4 3
 
5
-mysql:
6
-  image: mysql:5.7
7
-  volumes_from:
8
-    - mysqldata
9
-  environment:
10
-    MYSQL_ROOT_PASSWORD: myrootpassword
11
-    MYSQL_DATABASE: huginn
12
-    MYSQL_USER: huginn
13
-    MYSQL_PASSWORD: myhuginnpassword
4
+services:
5
+  mysqldata:
6
+    image: mysql:5.7
7
+    command: /bin/true
14 8
 
15
-huginn:
16
-  build: .
17
-  ports:
18
-    - 3000:3000
19
-  environment:
20
-    HUGINN_DATABASE_NAME: huginn
21
-    HUGINN_DATABASE_USERNAME: root
22
-    HUGINN_DATABASE_PASSWORD: myrootpassword
23
-    INTENTIONALLY_SLEEP: 10
24
-    #DATABASE_INITIAL_CONNECT_MAX_RETRIES: 5
25
-    PORT: 3000
26
-  links:
27
-    - mysql
9
+  mysql:
10
+    image: mysql:5.7
11
+    volumes_from:
12
+      - mysqldata
13
+    ports:
14
+      - "3306:3306"
15
+    environment:
16
+      MYSQL_ROOT_PASSWORD: myrootpassword
17
+      MYSQL_DATABASE: huginn
18
+      MYSQL_USER: huginn
19
+      MYSQL_PASSWORD: myhuginnpassword
28 20
 
21
+  huginn:
22
+    build:
23
+      context: ../../
24
+      dockerfile: docker/multi-process/Dockerfile
25
+    restart: always
26
+    environment:
27
+      HUGINN_DATABASE_NAME: huginn
28
+      HUGINN_DATABASE_USERNAME: root
29
+      HUGINN_DATABASE_PASSWORD: myrootpassword
30
+      INTENTIONALLY_SLEEP: 10
31
+      #DATABASE_INITIAL_CONNECT_MAX_RETRIES: 5
32
+      PORT: 3000
33
+      MYSQL_PORT_3306_TCP_ADDR: mysql
34
+      MYSQL_PORT_3306_TCP_PORT: 3306
35
+    ports:
36
+      - 3000:3000
37
+    links:
38
+      - mysql

+ 1 - 1
docker/multi-process/scripts/init

@@ -46,7 +46,7 @@ echo "RAILS_SERVE_STATIC_FILES=true" >> .env
46 46
 
47 47
 chmod ugo+r /app/.env
48 48
 source /app/.env
49
-sudo -u huginn -H bundle install --deployment --without test
49
+sudo -u huginn -H bundle install --without test development --path vendor/bundle
50 50
 
51 51
 # use default port number if it is still not set
52 52
 case "${DATABASE_ADAPTER}" in

+ 8 - 0
docker/single-process/scripts/prepare

@@ -38,3 +38,11 @@ rm -rf /usr/share/doc/
38 38
 rm -rf /usr/share/man/
39 39
 rm -rf /usr/share/locale/
40 40
 rm -rf /var/log/*
41
+
42
+# add a huginn group and user
43
+adduser --group huginn
44
+adduser --disabled-login --ingroup huginn --gecos 'Huginn' --no-create-home --home /app huginn
45
+passwd -d huginn
46
+
47
+mkdir -p /app/lib/
48
+mkdir -p /app/vendor/gems

+ 28 - 0
docker/scripts/setup

@@ -0,0 +1,28 @@
1
+#!/bin/bash
2
+set -e
3
+
4
+cd /app
5
+
6
+export LC_ALL=en_US.UTF-8
7
+
8
+# Ensure the huginn user has access to the required directories
9
+sudo -u huginn -H mkdir -p tmp/pids tmp/cache tmp/sockets log
10
+sudo -u huginn -H touch log/production.log
11
+# Get rid of annoying "fatal: Not a git repository (or any of the parent directories): .git" messages
12
+sudo -u huginn -H git init
13
+
14
+# HACK: We need a database connection to precompile the assets, use sqlite for that
15
+cp Gemfile Gemfile.bak
16
+echo "gem 'sqlite3', '~> 1.3.11'" >> /app/Gemfile
17
+RAILS_ENV=production APP_SECRET_TOKEN=secret DATABASE_ADAPTER=sqlite3 ON_HEROKU=true bundle install --without test development --path vendor/bundle -j 4
18
+RAILS_ENV=production APP_SECRET_TOKEN=secret DATABASE_ADAPTER=sqlite3 ON_HEROKU=true bundle exec rake assets:clean assets:precompile
19
+
20
+# Bundle again to get rid of the sqlite3 gem
21
+cp Gemfile.bak Gemfile
22
+RAILS_ENV=production APP_SECRET_TOKEN=secret DATABASE_ADAPTER=sqlite3 ON_HEROKU=true bundle install --without test development --path vendor/bundle -j 4
23
+
24
+# Configure the unicorn server
25
+mv config/unicorn.rb.example config/unicorn.rb
26
+sed -ri 's/^listen .*$/listen ENV["PORT"]/' config/unicorn.rb
27
+sed -ri 's/^stderr_path.*$//' config/unicorn.rb
28
+sed -ri 's/^stdout_path.*$//' config/unicorn.rb

+ 13 - 5
docker/single-process/Dockerfile

@@ -1,15 +1,23 @@
1 1
 FROM ubuntu:14.04
2 2
 MAINTAINER Dominik Sander
3 3
 
4
-ADD scripts/prepare /scripts/prepare
4
+ADD docker/scripts/prepare /scripts/prepare
5 5
 RUN /scripts/prepare
6 6
 
7
-ADD scripts/setup /scripts/setup
8
-RUN /scripts/setup
9
-
10 7
 WORKDIR /app
11 8
 
12
-ADD scripts/init /scripts/init
9
+ADD ["Gemfile", "Gemfile.lock", "/app/"]
10
+ADD lib/gemfile_helper.rb /app/lib/
11
+ADD vendor/gems /app/vendor/gems
12
+
13
+RUN chown -R huginn:huginn /app && \
14
+    sudo -u huginn -H echo "gem 'sqlite3', '~> 1.3.11'" >> /app/Gemfile && \
15
+    sudo -u huginn -H LC_ALL=en_US.UTF-8 RAILS_ENV=production ON_HEROKU=true bundle install --without test development --path vendor/bundle -j 4
16
+COPY . /app
17
+
18
+ADD ["docker/scripts/setup", "docker/single-process/scripts/init", "/scripts/"]
19
+
20
+RUN /scripts/setup
13 21
 
14 22
 EXPOSE 3000
15 23
 

+ 2 - 2
docker/single-process/README.md

@@ -81,9 +81,9 @@ For variables in the .env.example that are commented out, the default is to not
81 81
 
82 82
 ## Building on your own
83 83
 
84
-You don't need to do this on your own, but if you really want:
84
+You don't need to do this on your own, but if you really want run this command in the Huginn root directory:
85 85
 
86
-    docker build --rm=true --tag={yourname}/huginn .
86
+    docker build --rm=true --tag={yourname}/huginn -f docker/single-process/Dockerfile .
87 87
 
88 88
 ## Source
89 89
 

+ 51 - 31
docker/single-process/develop.yml

@@ -1,35 +1,55 @@
1
-mysqldata:
2
-  image: mysql:5.7
3
-  command: /bin/true
1
+# This needs at least compose 1.6.0
2
+version: '2'
4 3
 
5
-mysql:
6
-  image: mysql:5.7
7
-  volumes_from:
8
-    - mysqldata
9
-  environment:
10
-    MYSQL_ROOT_PASSWORD: myrootpassword
11
-    MYSQL_DATABASE: huginn
12
-    MYSQL_USER: huginn
13
-    MYSQL_PASSWORD: myhuginnpassword
4
+services:
5
+  mysqldata:
6
+    image: mysql:5.7
7
+    command: /bin/true
14 8
 
15
-huginn_web:
16
-  build: .
17
-  restart: always
18
-  extends:
19
-    file: environment.yml
20
-    service: huginn_base
21
-  ports:
22
-    - 3000:3000
23
-  links:
24
-    - mysql
9
+  mysql:
10
+    image: mysql:5.7
11
+    volumes_from:
12
+      - mysqldata
13
+    ports:
14
+      - "3306:3306"
15
+    environment:
16
+      MYSQL_ROOT_PASSWORD: myrootpassword
17
+      MYSQL_DATABASE: huginn
18
+      MYSQL_USER: huginn
19
+      MYSQL_PASSWORD: myhuginnpassword
25 20
 
26
-huginn_threaded:
27
-  build: .
28
-  restart: always
29
-  extends:
30
-    file: environment.yml
31
-    service: huginn_base
32
-  links:
33
-    - mysql
34
-  command: /scripts/init bin/threaded.rb
21
+  huginn_web:
22
+    build:
23
+      context: ../../
24
+      dockerfile: docker/single-process/Dockerfile
25
+    restart: always
26
+    environment:
27
+      DATABASE_ADAPTER: mysql2
28
+      DATABASE_NAME: huginn
29
+      DATABASE_USERNAME: huginn
30
+      DATABASE_PASSWORD: myhuginnpassword
31
+      APP_SECRET_TOKEN: 3bd139f9186b31a85336bb89cd1a1337078921134b2f48e022fd09c234d764d3e19b018b2ab789c6e0e04a1ac9e3365116368049660234c2038dc9990513d49c
32
+      MYSQL_PORT_3306_TCP_ADDR: mysql
33
+      MYSQL_PORT_3306_TCP_PORT: 3306
34
+    ports:
35
+      - 3000:3000
36
+    links:
37
+      - mysql
38
+
39
+  huginn_threaded:
40
+    build:
41
+      context: ../../
42
+      dockerfile: docker/single-process/Dockerfile
43
+    restart: always
44
+    environment:
45
+      DATABASE_ADAPTER: mysql2
46
+      DATABASE_NAME: huginn
47
+      DATABASE_USERNAME: huginn
48
+      DATABASE_PASSWORD: myhuginnpassword
49
+      APP_SECRET_TOKEN: 3bd139f9186b31a85336bb89cd1a1337078921134b2f48e022fd09c234d764d3e19b018b2ab789c6e0e04a1ac9e3365116368049660234c2038dc9990513d49c
50
+      MYSQL_PORT_3306_TCP_ADDR: mysql
51
+      MYSQL_PORT_3306_TCP_PORT: 3306
52
+    links:
53
+      - mysql
54
+    command: /scripts/init bin/threaded.rb
35 55
 

+ 0 - 36
docker/single-process/scripts/setup

@@ -1,36 +0,0 @@
1
-#!/bin/bash
2
-set -e
3
-
4
-# add a huginn group and user
5
-adduser --group huginn
6
-adduser --disabled-login --ingroup huginn --gecos 'Huginn' --no-create-home --home /app huginn
7
-passwd -d huginn
8
-
9
-# Shallow clone the huginn project repo
10
-git clone --depth 1 https://github.com/cantino/huginn /app
11
-
12
-# Change the ownership to huginn
13
-chown -R huginn:huginn /app
14
-
15
-cd app
16
-
17
-# create required tmp and log directories
18
-sudo -u huginn -H mkdir -p tmp/pids tmp/cache tmp/sockets log
19
-chmod -R u+rwX log tmp
20
-
21
-export LC_ALL=en_US.UTF-8
22
-
23
-# HACK: We need a database connection to precompile the assets, use sqlite for that
24
-echo "gem 'sqlite3', '~> 1.3.11'" >> Gemfile
25
-sudo -u huginn -H RAILS_ENV=production APP_SECRET_TOKEN=secret DATABASE_ADAPTER=sqlite3 ON_HEROKU=true bundle install --without test development --path vendor/bundle -j 4
26
-sudo -u huginn -H RAILS_ENV=production APP_SECRET_TOKEN=secret DATABASE_ADAPTER=sqlite3 ON_HEROKU=true bundle exec rake assets:clean assets:precompile
27
-git checkout Gemfile
28
-
29
-# Bundle again to get rid of the sqlite3 gem
30
-sudo -u huginn -H ON_HEROKU=true DATABASE_ADAPTER=noop bundle install --without test development --path vendor/bundle
31
-
32
-# Configure the unicorn server
33
-mv config/unicorn.rb.example config/unicorn.rb
34
-sed -ri 's/^listen .*$/listen ENV["PORT"]/' config/unicorn.rb
35
-sed -ri 's/^stderr_path.*$//' config/unicorn.rb
36
-sed -ri 's/^stdout_path.*$//' config/unicorn.rb